package com.distribute.framework.core.lang;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


public class Message implements java.io.Serializable{
	private static final long serialVersionUID = 1L;
	
	public String msgId;//消息ID
	public String msgType;//消息类型
	public String from;//发送人
	public String to;//接收人
	public String flag;//标识
	public Date timestamp;//消息时间
	public String title;//消息标题
	public String contentType;//内容类型
	public String content;//内容
	public String url;//链接地址
	public Map<String,Object> payload = new HashMap();//透传消息
	
	public static enum ContentType{
		txt,img,audio,file,data
	}
	
	public Message() {
		this.msgId = UUID.randomUUID().toString();
		this.timestamp = new Date();
	}
	
	/**
	 * @param msgType
	 * @param from
	 * @param to
	 * @param dataFlag
	 * @param title
	 * @param contentType
	 * @param content
	 * @param url 链接地址
	 */
	public Message(String msgType, String from, String to, String dataFlag,String title,ContentType contentType, String content,String linkUrl) {
		super();
		this.msgType = msgType;
		this.from = from;
		this.to = to;
		this.flag = dataFlag;
		this.title = title;
		this.contentType = contentType.name();
		this.content = content;
		this.url = linkUrl;
	}

	public static Message create(String msgType, String from, String to, String dataFlag,String title,ContentType contentType, String content,String linkUrl) {
		return new Message(msgType, from, to, dataFlag,title,contentType,content,linkUrl);
	}
	
	public String getMsgId() {
		return msgId;
	}
	public Message setMsgId(String msgId) {
		this.msgId = msgId;
		return this;
	}
	public String getMsgType() {
		return msgType;
	}
	public Message setMsgType(String msgType) {
		this.msgType = msgType;
		return this;
	}
	public String getFrom() {
		return from;
	}
	public Message setFrom(String from) {
		this.from = from;
		return this;
	}
	public String getTo() {
		return to;
	}
	public Message setTo(String to) {
		this.to = to;
		return this;
	}
	public String getFlag() {
		return flag;
	}
	public Message setFlag(String flag) {
		this.flag = flag;
		return this;
	}
	public Date getTimestamp() {
		return timestamp;
	}
	public Message setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
		return this;
	}
	public String getContentType() {
		return contentType;
	}
	public Message setContentType(String contentType) {
		this.contentType = contentType;
		return this;
	}
	public String getContent() {
		return content;
	}
	public Message setContent(String content) {
		this.content = content;
		return this;
	}
	public Map<String, Object> getPayload() {
		return payload;
	}
	public Message setPayload(Map<String, Object> payload) {
		this.payload = payload;
		return this;
	}
	public Message addPayload(String key,Object value) {
		this.payload.put(key, value);
		return this;
	}
	public String getTitle() {
		return title;
	}
	public Message setTitle(String title) {
		this.title = title;
		return this;
	}
	public String getUrl() {
		return url;
	}
	public Message setUrl(String url) {
		this.url = url;
		return this;
	}
}